package com.ejiaoyi.common.enums;

import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 系统配置信息键值对 枚举类
 *
 * @author unknownChivalrous
 * @since 2020-03-31
 */
@Getter
public enum ConfigMapEnum {
    // invoice part
    INVOICE_SALE_ACCOUNT("invoice_sale_account", "销方账号", "说明提示", ConfigType.INVOICE),
    INVOICE_SALE_PHONE("invoice_sale_phone", "销方电话", "电话", ConfigType.INVOICE),
    INVOICE_SALE_ADDRESS("invoice_sale_address", "销方地址", "销方地址", ConfigType.INVOICE),
    INVOICE_SALE_TAX_NUM("invoice_sale_tax_num", "销方税号", "", ConfigType.INVOICE),
    INVOICE_CLERK("invoice_clerk", "开票员", "开票员", ConfigType.INVOICE),
    INVOICE_PAYEE("invoice_payee", "收款", "收款", ConfigType.INVOICE),
    INVOICE_CHECKER("invoice_checker", "复核", "", ConfigType.INVOICE),
    INVOICE_LINE("invoice_line", "发票种类", "发票种类", ConfigType.INVOICE),

    // cert part
    CERT_NO("cert_no", "证书账号", "证书账号", ConfigType.CERT),
    CERT_NO1("cert_no1", "证书账号1", "", ConfigType.CERT),

    // demo part
    DEMO_NO("demo_no", "案例编号", "案例编号", ConfigType.DEMO),
    DEMO_NAME("demo_name", "案例名称", "案例名称", ConfigType.DEMO);

    /**
     * 系统配置KEY
     */
    String code;

    /**
     * 系统配置名称
     */
    String des;

    /**
     * 系统配置详细说明
     */
    String remark;

    public String getCode() {
        return code;
    }

    public String getDes() {
        return des;
    }

    public String getRemark() {
        return remark;
    }

    /**
     * 系统配置类型
     */
    ConfigType configType;

    ConfigMapEnum(String code, String des, String remark, ConfigType configType) {
        this.code = code;
        this.des = des;
        this.remark = remark;
        this.configType = configType;
    }

    public static List<ConfigMapEnum> getEnum(ConfigType configType) {
        List<ConfigMapEnum> configMaps = new ArrayList<>();

        ConfigMapEnum[] maps = ConfigMapEnum.values();

        for (ConfigMapEnum map : maps) {
            System.out.println(map);
            if (map.configType == configType) {
                configMaps.add(map);
            }
        }

        return configMaps;
    }

    /**
     * 系统配置类型
     */
    public enum ConfigType {
        INVOICE("invoice", "电子发票信息"),
        CERT("cert", "数字证书信息"),
        DEMO("demo", "测试DEMO信息");

        /**
         * 系统配置类型代码
         */
        String code;

        /**
         * 说明
         */
        String des;


        /**
         * 系统配置信息键值对
         */
        List<ConfigMapEnum> configMaps;

        public String getCode() {
            return code;
        }

        public String getDes() {
            return des;
        }


        public List<ConfigMapEnum> getConfigMaps() {
            return configMaps;
        }

        public void setConfigMaps(List<ConfigMapEnum> configMaps) {
            this.configMaps = configMaps;
        }

        ConfigType(String code, String des) {
            this.code = code;
            this.des = des;
        }

        public static ConfigType getEnum(String code) {
            ConfigType[] configTypes = ConfigType.values();
            for (ConfigType configType : configTypes) {
                if (StringUtils.equals(code, configType.getCode())) {
                    return configType;
                }
            }

            return null;
        }

        /**
         * 获取配置分类列表，用于动态显示选项卡
         *
         * @return 配置分类列表
         */
        public static List<ConfigType> listConfigType() {
            List<ConfigType> configTypeList = new ArrayList<>();
            ConfigType[] configTypes = ConfigType.values();
            for (ConfigType configType : configTypes) {
                configTypeList.add(configType);
            }
            return configTypeList;
        }
    }
}
